﻿using AutoTest.Business.Dto.Order;
using AutoTest.Business.IServices;
using AutoTest.Business.Vo.Order;
using AutoTest.Common.Extension;
using AutoTest.Domain;
using AutoTest.Framework.Api;
using Microsoft.AspNetCore.Mvc;
using Serilog;

namespace AutoTest.WebApi.Controllers
{
    /// <summary>
    /// 订单服务
    /// </summary>
    [Route("api/order")]
    public class OrderController(IOrderService orderService) : Controller
    {
        private readonly IOrderService _orderService = orderService;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="params"></param>
        /// <returns></returns>
        [HttpPost("buy-goods")]
        public async Task<ApiResult<CreateOrderResultVo<IDictionary<string, string>>>> BuyProduct([FromBody] CreateOrderDto @params)
        {
            var ip = string.Empty;
            ip = HttpContext.GetClientUserIp();
            @params.IP = ip;
            return await ApiResult<CreateOrderResultVo<IDictionary<string, string>>>.Successed(async () => await _orderService.BuyGoodsAsync(@params));
        }
        /// <summary>
        /// 微信支付回调
        /// </summary>
        /// <returns></returns>
        [HttpPost("wx/callback")]
        public async Task<string> WxCallBack()
        {
            var reader = new StreamReader(Request.Body);
            var content = await reader.ReadToEndAsync();
            Log.Information("收到微信支付回调消息："+content);
            //string ret = _OrderService.WechatPayCallBack(xml);
            return AppConsts.TENPAY_CALLBACK_RESULT_FAIL;
        }
    }
}
